package Service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import Model.Shebeilog;
import Dao.ShebeilogMapper;
import Service.ShebeilogService;
import utils.ReturnData;
import utils.ReturnDataForLayui;
import utils.UpdateOrInsertResultDeal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import utils.permission.PageDataResult;

import javax.servlet.http.HttpSession;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

@Service
public class ShebeilogServiceImpl implements ShebeilogService {
    @Autowired
    private ShebeilogMapper shebeilogMapper;

    @Transactional(propagation = Propagation.REQUIRED, readOnly = true)
    @Override
    public ReturnDataForLayui getList(Shebeilog shebeilog) {
        PageHelper.startPage(shebeilog.getPage(), shebeilog.getLimit());
        List<Shebeilog> list = shebeilogMapper.getList(shebeilog);
        PageInfo<Shebeilog> info = new PageInfo<>(list);
        return ReturnDataForLayui.success(list, info.getTotal());
    }

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public ReturnData add(Shebeilog shebeilog) {
        int i = shebeilogMapper.add(shebeilog);
        return UpdateOrInsertResultDeal.dealWith(i);
    }

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public ReturnData delete(Shebeilog shebeilog) {
        int i = shebeilogMapper.delete(shebeilog);
        return UpdateOrInsertResultDeal.dealWith(i);
    }


    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public ReturnData update(Shebeilog shebeilog) {
        int i = shebeilogMapper.update(shebeilog);
        return UpdateOrInsertResultDeal.dealWith(i);
    }


}